//! @Author: DengLibin
//! @Date: Create in 2023-09-25 14:15:38
//! @Description: 拼音 https://crates.io/crates/pinyin

use pinyin::ToPinyin;

/// @Author: DengLibin
/// @Date: Create in 2023-09-25 14:17:39
/// @Description: 获取中文拼音
pub fn get_pinyin(chinese: &str) -> String {
    let mut r_str = String::new();
    for ch in chinese.chars() {
        if unicode_blocks::is_cjk(ch) {
            //是中文 cjk：中日韩统一表意文字
            let pinyin = ch.to_pinyin();
            if let Some(p) = pinyin {
                r_str.push_str(p.plain());
            }
        } else {
            r_str.push(ch);
        }
    }
    return r_str;
}
/// @Author: DengLibin
/// @Date: Create in 2023-09-25 14:57:06
/// @Description: 获取中文每个字拼音首字母大写
pub fn get_first_upper(chinese: &str) -> String {
    let mut r_str = String::new();

    for pinyin in chinese.to_pinyin() {
        if let Some(p) = pinyin {
            let p = p.plain();
            let first = &p[0..1]; // 取首字母
            r_str.push_str(first.to_uppercase().as_str())
        }
    }

    return r_str;
}
